< previous page page_433 next page >

Page 433
You can use each of the preceding methods to draw on an object. Before I cover each method in more detail, though, I should mention that certain properties of the object being drawn on affect the way these methods work. These properties are listed in Table 19.2.
Table 19.2 Drawing Properties That Affect the Appearance of Graphics
Property NamePurpose
DrawModeDetermines how the drawing color interacts with the colors already present on the object
DrawStyleSets a drawing pattern
DrawWidthSets the border width of lines and circles
FillColorDetermines the color used to fill a rectangle or circle
FillStyleDetermines the pattern used to fill a rectangle or circle
ForeColorDetermines the primary color used to draw with the graphics methods, if no color is specified in the method call
AutoRedrawDetermines whether the output of the graphics methods is automatically refreshed when the window has been obscured (Form and PictureBox only)

Lines and Circles
You use the Line method to draw lines and boxes. To draw lines, supply the starting and ending points of the line on a coordinate system whose origin is in the upper-left corner. The following statements, for example, draw a green line from the upper-left corner of a form to the lower-right corner:
    Dim x2 As Single, y2 As Single
    x2 = Form1.ScaleWidth
    y2 = Form1.ScaleHeight
    Line (0, 0)-(x2, y2),vbGreen
If you omit the starting point of the line, the current position becomes the starting point. The current position is the ending point of the last line, or you can set it with the object's CurrentX and CurrentY properties. For example, the following code uses the Line method to draw a triangle on a form. In each call to the Line method, note that the first set of coordinates is omitted.
Private Sub Form_Click()
    Form1.CurrentX = 1500
    Form1.CurrentY = 750
    Line -(2000, 750), vbRed
    Line -(2000, 1250), vbBlue
    Line -(1500, 750)
End Sub
In the last of the preceding code segment statements, the optional parameter for the color of the line is omitted. If no color is specified, the line is drawn in the color specified in the object's

 
< previous page page_433 next page >